package com.lg.partition28;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author `RKC`
 * @date 2022/3/18 8:46
 */
public class P2704炮兵阵地 {

    private static final int N = 101, M = 11;
    private static int[] g = new int[N];
    private static int[][][] f = new int[2][1 << M][1 << M];
    private static Map<Integer, List<Integer>> map = new HashMap<>(N);
    private static int n, m;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        for (int i = 1; i <= n; i++) {
            String s = reader.readLine();
            for (int j = 1; j <= m; j++) {
                if (s.charAt(j - 1) == 'H') g[i] |= 1 << (j - 1);
            }
        }
        //预处理出单行合法状态
        for (int i = 0; i < 1 << m; i++) {
            if ((i & i << 1) != 0 || (i & i << 2) != 0) continue;
            map.put(i, new ArrayList<>());
        }
        for (Map.Entry<Integer, List<Integer>> entry : map.entrySet()) {
            int cur = entry.getKey();
            List<Integer> ls = entry.getValue();
            for (int prev : map.keySet()) {
                if ((cur & prev) != 0) continue;
                ls.add(prev);
            }
        }
        for (int i = 1; i <= n; i++) {
            for (Map.Entry<Integer, List<Integer>> entry : map.entrySet()) {
                int cur = entry.getKey(), cnt = bitCount(cur);
                if ((cur & g[i]) != 0) continue;
                List<Integer> ls1 = entry.getValue();
                for (int prev1 : ls1) {
                    List<Integer> ls2 = map.get(prev1);
                    for (int prev2 : ls2) {
                        if ((cur & prev2) != 0) continue;
                        f[i & 1][cur][prev1] = Math.max(f[i & 1][cur][prev1], f[i - 1 & 1][prev1][prev2] + cnt);
                    }
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < 1 << m; i++) {
            for (int j = 0; j < 1 << m; j++) {
                ans = Math.max(ans, f[n & 1][i][j]);
            }
        }
        writer.write(ans + "\n");
        writer.flush();
    }

    private static int bitCount(int x) {
        int res = 0;
        while (x != 0) {
            res++;
            x -= x & -x;
        }
        return res;
    }
}
